<!DOCTYPE html>
<html lang="zh-cn">

<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
  <title>成功案例</title>


  <!-- Expand styles -->
  <link href="../css/app/app.css" rel="stylesheet">
  <link href="../css/app/default.css" rel="stylesheet">
  <link href="../css/mui/mui.css" rel="stylesheet">


</head>

<body>

  <!-- header -->
  <div id="pullrefresh" class="mui-content mui-scroll-wrapper">
    <div class="mui-scroll">
      <div class="trade-list">

      </div>
    </div>
  </div>




  <script src="../js/dsbridge.js"></script>
  <script src="../js/jquery.js"></script>
  <script src="../js/mui/mui.js"></script>
  <script src="../js/layer.js"></script>
  <script src="../js/mui/mui.picker.min.js"></script>
  <script src="../js/app/app-base.js"></script>
  <script src="../js/app/app-url.js"></script>
  <script src="../js/app/app-ajax.js"></script>

  <script>
    var page = 1;
    var limit = 10;
    var index = 0;

    var all_data = new Array();
    $(document).ready(function () {

      mui.init({
        pullRefresh: {
          container: '#pullrefresh',
          down: {
            auto: true, // 首次进入自动加载
            callback: pulldownRefresh
          },
          up: {
            contentrefresh: '正在加载...',
            callback: pullupRefresh
          }
        }
      });

    })

    dsBridge.register('addCase', function () {
      localStorage.setItem("case-edit-id", '');
    })




    /**
     * 下拉刷新具体业务实现
     */
    function pulldownRefresh() {

      page = 1;
      var data = {
        orgUserAccId: getUserId(),
        page: page,
        limit: limit
      }
      getServerData(url_queryOffLineList, data);
    }

    /**
     * 上拉加载具体业务实现
     */
    function pullupRefresh() {
      page++;
      var data = {
        orgUserAccId: getUserId(),
        page: page,
        limit: limit
      }
      getServerData(url_queryOffLineList, data);
    }


    function getServerDataSuccess(url, data) {
      switch (url) {
        case url_queryOffLineList:
          var list = data.data;
          var html_data = '';
          var tranType = "";
          if (list != null && list.length > 0) {
            $.each(list, function (index, item) {
              
              if(item.tranType!=null){
                tranType = '<span class="tuli-content1 font-14 tuli-bg" style="margin-left:5px;">' + item.tranType.name + '</span>';
              }else{
                tranType = "";
              }
              html_data += '<div class="margin-b-10">' +
                '<div class="widget-default widget-body display-flex margin-b-1 padding-b-10 case-details" id="' + item.id + '">' +
                '<div class="position-img-l2">' +
                '<img src="' + (isEmpty(item.img) ? "../img/bg_default.png" : showSmallImg(item.img)) + '" alt="">' +
                '</div>' +
                '<div class="display-flex flex-column margin-l-10 margin-t-f5">' +
                '<p class="no-margin font-16 font-weight black1 elli1">' + item.title + '</p>' +
                '<div class="padding-t-5 padding-b-5">' + tranType + 
                '</div>' +
                '<p class="font-12 gray no-margin line-height-18">主办方：' + item.tranSponsors + '</p > ' +
                '<p class="font-12 gray no-margin line-height-18">' + item.tranBeginTime + '<span>&nbsp;&nbsp;~&nbsp;&nbsp;</span>' + item.tranEndTime + '</p>' +
                '</div>' +
                '</div>' +
                '<div class="text-right padding-10-15 widget-default">' +
                '<span class="tuli-content2 font-13 edit-btn" id="' + item.id + '">编辑</span>' +
                '<span class="tuli-content2 font-13 delete-btn" id="' + item.id + '"> 删除</span>' +
                '</div>' +
                '</div>';
              index++;

            })
          }

          if (page == 1) {
            mui('#pullrefresh').pullRefresh().endPulldownToRefresh();
            if (list.length > 0) {
              mui('#pullrefresh').pullRefresh().refresh(true);
            }
            $(".trade-list").html(html_data);
          } else {
            $(".trade-list").append(html_data);
            mui('#pullrefresh').pullRefresh().endPullupToRefresh(list.length != limit);
          }
          break;
        case url_deleteOffLine:
          pulldownRefresh();
          layer.open({
            content: '删除成功',
            btn: ['确定'],
            yes: function (index) {
              layer.close(index);
            }
          })
          break;

      }
    }

    mui(".trade-list").on('tap', '.edit-btn', function () {
      localStorage.setItem("case-edit-id", $(this).attr("id"));
      dsBridge.call("goEdit");

    });


    mui(".trade-list").on('tap', '.case-details', function () {
      localStorage.setItem("case-id", $(this).attr("id"));
      dsBridge.call("details");
    });


    mui(".trade-list").on('tap', '.delete-btn', function () {

      var pid = $(this).attr("id");

      layer.open({
        content: '是否删除该条记录？',
        btn: ['删除', '取消'],
        yes: function (index) {
          var data = {
            id: pid
          }
          getServerData(url_deleteOffLine, data, "POST");
          layer.close(index);
        }
      });

    });



  </script>


</body>

</html>